//
//  BkRealNamePersonalInfoView.m
//  bestkeep
//
//  Created by windCould on 16/11/30.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BkRealNamePersonalInfoView.h"
#import "BKMyCommon.h"

@interface BkRealNamePersonalInfoView ()

@property (nonatomic,strong)UILabel * nameLab;
@property (nonatomic,strong)UITextField * nameTexField;
@property (nonatomic,strong)UIView * bottomLine1;

@property (nonatomic,strong)UILabel * identifyCardLab;
@property (nonatomic,strong)UITextField * identifyNumTexField;
@property (nonatomic,strong)UIView * bottomLine2;

@property (nonatomic,strong)UILabel * availableDurLab;
@property (nonatomic,strong)UILabel * availabDurContentLab;
@property (nonatomic,strong)UILabel * unlimitLab;
@property (nonatomic,strong)UIButton * unlimitBtn;
@property (nonatomic,strong)UIView * bottomLine3;

@property (nonatomic,strong)UIControl * tapControl;


@property (nonatomic,strong)UILabel * accountAddressLab;
@property (nonatomic,strong)UITextView * accountAddressTexView;

@end


@implementation BkRealNamePersonalInfoView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.userInteractionEnabled = YES;
        [self setUpViews];
        self.backgroundColor = [UIColor whiteColor];
    }
    
    return  self;
}

-(void)setAvailableTimeStr:(NSString *)availableTimeStr
{
    self.availabDurContentLab.text = availableTimeStr;
    if (![availableTimeStr isEqualToString:@"9999年12月31日"]) {
        
        self.unlimitBtn.selected = NO;
    } else {
    
        self.unlimitBtn.selected = YES;
    }
    
    
}

-(NSString *)userRealNameStr
{
    NSString * str = _nameTexField.text == nil ? @"":_nameTexField.text;
    return str;
}

-(NSString *)identifiCardIdStr
{
    NSString * str = _identifyNumTexField.text == nil ? @"":_identifyNumTexField.text;
    return str;
}

-(NSString *)availableTimeStr
{
    NSString * str = _availabDurContentLab.text == nil ? @"":_availabDurContentLab.text;
    return str;
}

-(NSString *)deatailAddressStr
{
    NSString * str = _accountAddressTexView.text == nil ? @"":_accountAddressTexView.text;
    
    return str;
}


#pragma mark =========================Function===============================

-(void)isForeverAailable
{
    if (self.unlimitBtn.isSelected) {
        
        self.unlimitBtn.selected = NO;
        self.availabDurContentLab.text = @"";
        
    } else {
    
        self.unlimitBtn.selected = YES;
        self.availabDurContentLab.text = @"9999年12月31日";
    }
    
    if ([self.myDelegate respondsToSelector:@selector(bkRealNamePersonalInfoView:setForevreTime:)]) {
        
        [self.myDelegate bkRealNamePersonalInfoView:self setForevreTime:_unlimitBtn.selected];
    }
    
    
    
    
}

-(void)clickToSelectAvailbTime
{
    if ([self.myDelegate respondsToSelector:@selector(bkRealNamePersonalInfoView: avalableTimeValue:)]) {
        
        [self.myDelegate bkRealNamePersonalInfoView:self avalableTimeValue:self.availabDurContentLab];
    }
    
}

#pragma mark =========================布局===================================
-(void)setUpViews{
    
    _nameLab = [UILabel new];
    _nameLab.text = @"姓名:";
    _nameLab.textColor = RGBCOLOR(64, 64, 64, 1);
    _nameLab.font = [UIFont systemFontOfSize:15];
    [self addSubview:_nameLab];
  
    _nameTexField= [UITextField new];
    _nameTexField.placeholder = @"您的真实姓名";
    _nameTexField.textColor = RGBCOLOR(64, 64, 64, 1);
    _nameTexField.font = [UIFont systemFontOfSize:15];
    [self addSubview:_nameTexField];
    
    _bottomLine1 = [UIView new];
    _bottomLine1.backgroundColor = RGBCOLOR(242, 242, 242, 1);
    [self addSubview:_bottomLine1];
    
    _identifyCardLab = [UILabel new];
    _identifyCardLab.text = @"身份证号:";
    _identifyCardLab.textColor = RGBCOLOR(64, 64, 64, 1);
    _identifyCardLab.font = [UIFont systemFontOfSize:15];
    [self addSubview:_identifyCardLab];
    
    _identifyNumTexField = [UITextField new];
    _identifyNumTexField.placeholder = @"您的身份证号码 (将加密处理)";
    _identifyNumTexField.textColor = RGBCOLOR(64, 64, 64, 1);
    _identifyNumTexField.font = [UIFont systemFontOfSize:15];
    _identifyNumTexField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    [self addSubview:_identifyNumTexField];
    
    _bottomLine2 = [UIView new];
    _bottomLine2.backgroundColor = RGBCOLOR(242, 242, 242, 1);
    [self addSubview:_bottomLine2];
  
    _availableDurLab = [UILabel new];
    _availableDurLab.text = @"身份证有效期:";
    _availableDurLab.textColor = RGBCOLOR(64, 64, 64, 1);
    _availableDurLab.font = [UIFont systemFontOfSize:15];
    [self addSubview:_availableDurLab];

    _availabDurContentLab = [UILabel new];
    _availabDurContentLab.text = @"";
    _availabDurContentLab.textColor = RGBCOLOR(64, 64, 64, 1);
    _availabDurContentLab.font = [UIFont systemFontOfSize:15];
    _availabDurContentLab.userInteractionEnabled = YES;
    [self addSubview:_availabDurContentLab];
    
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickToSelectAvailbTime)];
    tap.numberOfTapsRequired = 1;
    _availabDurContentLab.userInteractionEnabled = YES;
    [_availabDurContentLab addGestureRecognizer:tap];
   
    
    _unlimitLab = [UILabel new];
    _unlimitLab.text = @"永久";
    _unlimitLab.textColor = RGBCOLOR(64, 64, 64, 1);
    _unlimitLab.font = [UIFont systemFontOfSize:15];
    [self addSubview:_unlimitLab];
    
    _unlimitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _unlimitBtn.selected = NO;
    [_unlimitBtn setBackgroundImage:[UIImage imageNamed:@"BK_My_椭圆-1"] forState:UIControlStateNormal];
    [_unlimitBtn setBackgroundImage:[UIImage imageNamed:@"BK_My_图层-5"] forState:UIControlStateSelected];
    [_unlimitBtn addTarget:self action:@selector(isForeverAailable) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_unlimitBtn];
    
    _bottomLine3 = [UIView new];
    _bottomLine3.backgroundColor = RGBCOLOR(242, 242, 242, 1);
    [self addSubview:_bottomLine3];
    
    _accountAddressLab = [UILabel new];
    _accountAddressLab.text  = @"身份证住址：";
    _accountAddressLab.textColor = RGBCOLOR(64, 64, 64, 1);
    _accountAddressLab.font = [UIFont systemFontOfSize:15];
    [self addSubview:_accountAddressLab];
    
    _accountAddressTexView = [UITextView new];
    _accountAddressTexView.textColor = RGBCOLOR(64, 64, 64, 1);
    _accountAddressTexView.font = [UIFont systemFontOfSize:15];
    [self addSubview:_accountAddressTexView];
    [self layoutViews];
}

-(void)layoutViews{
    
    [_nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.mas_top).offset(0);
        make.left.mas_equalTo(self.mas_left).offset(ApplicationBackGauge);
        make.size.mas_offset(CGSizeMake(45,40));
    }];
    
    [_nameTexField mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(_nameLab.mas_right);
        make.centerY.mas_equalTo(_nameLab.mas_centerY).offset(0);
        make.right.mas_equalTo(self.mas_right).offset(-ApplicationBackGauge);
    }];
    
    [_bottomLine1 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.mas_left).offset(0);
        make.right.mas_equalTo(self.mas_right).offset(0);
        make.height.mas_offset(@0.5);
        make.top.mas_equalTo(_nameLab.mas_bottom).offset(0);
    }];
    
    
    [_identifyCardLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(_nameLab.mas_left).offset(0);
        make.top.mas_equalTo(_bottomLine1.mas_bottom).offset(0);
        make.size.mas_equalTo(CGSizeMake(75, 40));
    }];
    
    [_identifyNumTexField mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(_identifyCardLab.mas_right).offset(0);
        make.centerY.mas_equalTo(_identifyCardLab.mas_centerY).offset(0);
        make.right.mas_equalTo(self.mas_right).offset(-ApplicationBackGauge);
    }];
    
    [_bottomLine2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.mas_left).offset(0);
        make.right.mas_equalTo(self.mas_right).offset(0);
        make.height.mas_offset(@0.5);
        make.top.mas_equalTo(_identifyCardLab.mas_bottom).offset(0);
    }];
    
    [_availableDurLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(_nameLab.mas_left).offset(0);
        make.top.mas_equalTo(_bottomLine2.mas_bottom).offset(0);
        make.size.mas_equalTo(CGSizeMake(105, 40));
    }];
    
    [_availabDurContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(_availableDurLab.mas_right).offset(0);
        make.centerY.mas_equalTo(_availableDurLab.mas_centerY).offset(0);
        make.width.mas_equalTo(@(SCREENWIDTH -189));
        make.height.mas_equalTo(@(40));
    }];
    /*
    [_tapControl mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(_availableDurLab.mas_right).offset(0);
        make.centerY.mas_equalTo(_availableDurLab.mas_centerY).offset(0);
        make.height.mas_equalTo(@(40));
    }];
     */
    
    [_unlimitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(_availableDurLab.mas_centerY).offset(0);
        make.size.mas_equalTo(CGSizeMake(19, 19));
        make.right.mas_equalTo(self.mas_right).offset(-20);
    }];
    

    [_unlimitLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(_unlimitBtn.mas_left);
        make.centerY.mas_equalTo(_availabDurContentLab.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    [_bottomLine3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(_availableDurLab.mas_bottom).offset(0);
        make.left.mas_equalTo(self.mas_left).offset(0);
        make.right.mas_equalTo(self.mas_right).offset(0);
        make.height.mas_equalTo(@(0.5));
    }];
    
    [_accountAddressLab mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.mas_left).offset(ApplicationBackGauge);
        make.top.mas_equalTo(_bottomLine3.mas_bottom).offset(10);
    }];
    
    [_accountAddressTexView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(_accountAddressLab.mas_right).offset(0);
        make.top.mas_equalTo(_bottomLine3.mas_bottom).offset(6);
        make.width.mas_equalTo(@(SCREENWIDTH-105));
        make.bottom.mas_equalTo(self.mas_bottom).offset(-10);
    }];
    
}

@end
